﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Infinity.ExpressionParser.Comparer;

namespace Infinity.ExpressionParser.Helpers
{
	public static class SetHelper
	{
		public static bool Contains(IEnumerable<object> set, object obj, IEqualityComparer<object> comparer)
		{
			return set.Contains(obj, comparer);
		}

		public static bool IsSubsetOf(IEnumerable<object> a, IEnumerable<object> b, IEqualityComparer<object> comparer)
		{
			HashSet<object> set = new HashSet<object>(a, comparer);
			return set.IsSubsetOf(b);
		}

		public static bool ISupersetOf(IEnumerable<object> a, IEnumerable<object> b, IEqualityComparer<object> comparer)
		{
			HashSet<object> set = new HashSet<object>(a, comparer);
			return set.IsSupersetOf(b);
		}

		public static object[] Union(IEnumerable<object> a, IEnumerable<object> b)
		{
			return a.Union(b, ObjectEqualityComparer.Instance).ToArray();
		}

		public static object[] Intersect(IEnumerable<object> a, IEnumerable<object> b)
		{
			return a.Intersect(b, ObjectEqualityComparer.Instance).ToArray();
		}

		public static object[] Except(IEnumerable<object> a, IEnumerable<object> b)
		{
			return a.Except(b, ObjectEqualityComparer.Instance).ToArray();
		}

		public static object[] ToSet(object[] objs)
		{
			return new HashSet<object>(objs, ObjectEqualityComparer.Instance).ToArray();
		}
	}
}
